"""Simple script to run the linear advection example"""

from hogs.grids import grid1d as grid

import hogs.solvers.linsolver as solvers
import hogs.solvers.flux.flux_functions as flux
import hogs.solvers.bc.api as bc

import numpy

# create a grid
g = grid.Grid1D(); g.initialize(xlow=0, xhigh=1.2, dx=0.01, nb=2, nvar=1)

# instantiate the solver
solver = solvers.LinearSolver(nvar = 1, tf = 6.0, grid=g)

# add the flux function
solver.flux_function = flux.AdvectionFlux1D(a=1)

# add the boundary conditions
solver.bc = bc.PeriodicBC()

# setup solver
solver.setup()

# set the print frequency
solver.set_print_frequency(pfreq=20)

q = g.q[0]
x = g.xc

for i, j in enumerate(x):
    if 0.45 < j < 0.75:
        q[i] = 1.0

# solve the system
solver.solve()
